﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace CCF20Model
{
    partial class VehicleType : IDataErrorInfo
    {

        public VehicleType()
        {
            
        }
        partial void OnManufactureChanged()
        {
            this.RemoveError("Manufacture");

            if (string.IsNullOrEmpty(this.Manufacture))
            {
                this.AddError("Manufacture", "生产厂商不可为空");

            }
        }
        
        partial void OnModelChanged()
        {
            this.RemoveError("Model");

            if (string.IsNullOrEmpty(this.Model))
            {
                this.AddError("Model", "车辆型号不可为空");

            }
        }
        partial void OnEngineTypeChanged()
        {
            this.RemoveError("EngineType");

            if (string.IsNullOrEmpty(this.EngineType))
            {
                this.AddError("EngineType", "引擎型号不可为空");

            }
        }

        partial void OnDisplacementChanged()
        {
            this.RemoveError("Displacement");

            if (string.IsNullOrEmpty(this.Displacement))
            {
                this.AddError("Displacement", "排气量不可为空");

            }
        }


        #region IDataErrorInfo Members

        private Dictionary<string, string> m_validationErrors = new Dictionary<string, string>();

        private void AddError(string columnName, string msg)
        {
            if (!m_validationErrors.ContainsKey(columnName))
            {
                m_validationErrors.Add(columnName, msg);
            }

        }

        private void RemoveError(string columnName)
        {
            if (m_validationErrors.ContainsKey(columnName))
            {
                m_validationErrors.Remove(columnName);
            }
        }

        public string Error
        {
            get
            {
                if (m_validationErrors.Count > 0)
                {
                    return "Customer data is invalid";
                }
                else return null;
            }
        }

        public string this[string columnName]
        {
            get
            {
                if (m_validationErrors.ContainsKey(columnName))
                {
                    return m_validationErrors[columnName];
                }
                else return null;
            }
        }

        #endregion
    }
}
